﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace foxAudio2Word
{
    /// <summary>
    /// 读写文件的静态类
    /// </summary>
    class MyFileIO
    {
        /// <summary>
        /// 读取文件操作
        /// </summary>
        /// <param name="path"></param>
        public static string Read(string path)
        {
            try
            {
                StreamReader sr = new StreamReader(path, Encoding.Default);
                String line;
                while ((line = sr.ReadLine()) != null)
                {
                    Console.WriteLine(line.ToString());
                }
                return "成功读取文件";
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
        }
        /// <summary>
        /// 写入文件操作
        /// </summary>
        /// <param name="path"></param>
        public static string Write(string path, string content)
        {
            try
            {
                FileStream fs = new FileStream(path, FileMode.Append);
                StreamWriter sw = new StreamWriter(fs);
                //开始写入
                sw.Write(content);
                //清空缓冲区
                sw.Flush();
                //关闭流
                sw.Close();
                fs.Close();
                return "成功写入文件";
            }
            catch (Exception ex)
            {
               return ex.ToString();
            }
            finally
            { }
        }
    }
}
